
package com.mp.chart.markerview;

import android.content.Context;
import android.util.TypedValue;
import android.view.View;
import android.widget.TextView;

import com.mp.chart.components.MarkerView;
import com.mp.chart.data.Entry;
import com.mp.chart.data.KLineData;
import com.mp.chart.data.MinutesData;
import com.android.R;

import java.text.DecimalFormat;

/*分时图左边的高亮*/
public class LeftMarkerView extends MarkerView {

    private final boolean isOut;
    private DecimalFormat mFormat;
    private TextView tvContent;
    private String strFormat;
    private String type;//com.mp.chart type

    public LeftMarkerView(String type, Context context, int layoutResource, boolean isOut, String format) {
        super(context, layoutResource);
        this.type = type;
        this.isOut = isOut;
        this.strFormat = format;
        tvContent = (TextView) findViewById(R.id.tvContent);
        View body = findViewById(R.id.llBody);
        if (mFormat != null)
            mFormat = new DecimalFormat(format);
       // tvContent.setTextColor(mTheme.getStockChartBackgroundColor());
        tvContent.setTextSize(TypedValue.COMPLEX_UNIT_DIP,10f);
        body.setBackgroundResource(R.drawable.market_select_marker);

    }

    @Override
    public void refreshContent(Entry e, int dataSetIndex) {
        if ("kline".equals(type)) {
            KLineData data = (KLineData) e.getData();
            if (data != null) {
                if (this.strFormat != null) {
                    mFormat = new DecimalFormat(strFormat);
                    tvContent.setText(mFormat.format(data.close));
                } else {
                    tvContent.setText(data.close + "");
                }
            } else {
                tvContent.setText("");
            }
        } else if ("timeline".equals(type)) {
            MinutesData data = (MinutesData) e.getData();
            if (data != null) {
                if (this.strFormat != null) {
                    mFormat = new DecimalFormat(strFormat);
                    tvContent.setText(mFormat.format(data.chengjiaojia));
                } else {
                    tvContent.setText(data.chengjiaojia + "");
                }
            } else {
                tvContent.setText("");
            }
        }




    }

     @Override
     public int getXOffset() {
         return isOut ? 0 : (getWidth());
     }

     @Override
     public int getYOffset() {
         return 0;
     }
 /*   @Override
    public int getXOffset() {
        return 0;
    }

    @Override
    public int getYOffset() {
        return 0;
    }*/
}
